#include "managewindow.h"
#include "ui_managewindow.h"

ManageWindow::ManageWindow(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::ManageWindow),
    m_stuPage(nullptr),
    m_bookPage(nullptr),
    m_recordPage(nullptr)
{
    ui->setupUi(this);

    /* 设置图标 */
    setWindowIcon(QIcon(":/pic/lib.jpg"));

    /* 设置标题 */
    setWindowTitle("图书管理系统/管理员");

    /* 页面初始化 */
    initPage();

    connect(this, &ManageWindow::close, m_recordPage, &manage_recordinfo::clearAll);   //管理员界面关闭，借阅记录查询界面清空
    connect(this, &ManageWindow::updataStuView, m_stuPage, &manage_stuinfo::updateView);
    connect(this, &ManageWindow::updataBookView, m_bookPage, &manage_bookinfo::updateView);
}

/* 管理员界面关闭事件 */
void ManageWindow::closeEvent(QCloseEvent *event)
{
    emit close();
}

/* 点击学生管理界面按钮 */
void ManageWindow::on_stuBtn_clicked()
{
    ui->stackedWidget->setCurrentIndex(0);
    emit updataStuView();
}

/* 点击图书管理界面按钮 */
void ManageWindow::on_bookBtn_clicked()
{
    ui->stackedWidget->setCurrentIndex(1);
    emit updataBookView();
}

/* 点击借阅记录界面按钮 */
void ManageWindow::on_recordBtn_clicked()
{
    ui->stackedWidget->setCurrentIndex(2);
}

/* 页面初始化 */
void ManageWindow::initPage()
{
    m_stuPage = new manage_stuinfo(this);
    m_bookPage = new manage_bookinfo(this);
    m_recordPage = new manage_recordinfo(this);
    ui->stackedWidget->addWidget(m_stuPage);
    ui->stackedWidget->addWidget(m_bookPage);
    ui->stackedWidget->addWidget(m_recordPage);
    ui->stackedWidget->setCurrentIndex(0);
}

ManageWindow::~ManageWindow()
{
    delete ui;
}
